package utilities;

import gameAppLayer.enums.Constants;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public final class HexLocationLoader {
	
	public static HashMap<Integer, ArrayList<Integer>> loadLocations(int radius) {
		
		String line;
		double dist = 0;
		String delims = "[\t+]";
		String[] pieces = new String[4];
		//ArrayList<ArrayList<Integer>> locations = new ArrayList<ArrayList<Integer>>();//new ArrayList<ArrayList<Integer>>();
		HashMap<Integer, ArrayList<Integer>> galaxyTileLocations = new HashMap<Integer, ArrayList<Integer>>();
		
		try {
			FileReader fr = new FileReader(Constants.dataPath + "//hexLocations.txt");
			BufferedReader br = new BufferedReader(fr);
			Integer i = 0;
			int tempRadius = (int) (radius + radius*(1-Math.cos(Math.PI/6)));
			boolean distFlag = true;
			//boolean singleDistFlag = true;
			while (distFlag) {
				line = br.readLine();
				if (line == null) {
					distFlag = false;
					//System.out.println("NULL");
				}
				else {
					pieces = line.split(delims);
					dist = Double.parseDouble(pieces[3]);
					
					if (dist < radius) {
						//distFlag = true;
						galaxyTileLocations.put(i, new ArrayList<Integer>());
						galaxyTileLocations.get(i).add(Integer.parseInt(pieces[0]));///
						galaxyTileLocations.get(i).add(Integer.parseInt(pieces[1]));///
						galaxyTileLocations.get(i).add(Integer.parseInt(pieces[2]));///
						
						
						
//						locations.add(new ArrayList<Integer>());
//						locations.get(i).add(Integer.parseInt(pieces[0]));///
//						locations.get(i).add(Integer.parseInt(pieces[1]));///
//						locations.get(i).add(Integer.parseInt(pieces[2]));///
//						i++;
					}	
				}		
				i++;
				
			}
			br.close();
		}
		catch (IOException e) {
			System.out.println("IOException: " + e);
		}
		
		return galaxyTileLocations;
		//return locations;
		
	}
	
	
	
	
}
